package com.server.thisService.common.helper;

import com.project.annotation.enums.common.ConstBaseString;
import com.project.annotation.function.ContextHolderBase;
import com.project.annotation.model.base.BaseContext;
import com.project.thisDatabase.base.model.UserInfoEntity;
import com.project.thisDatabase.base.service.ContextInterfaceBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class ContextValue implements ContextInterfaceBase {

    @Autowired
    private ContextHolderBase contextHolderBase;

    @Override
    public UserInfoEntity userInfo() {
        BaseContext context = contextHolderBase.getContext();
        UserInfoEntity en = new UserInfoEntity();
        en.setId(Long.parseLong(context.getUserId()));
        en.setUserCode(context.getUserCode());
        en.setUserName(context.getUserName());
        en.setToken(context.getToken());
        en.setPermissionCodes(Arrays.asList(context.getPermissionCodes()));
        en.setStatus(ConstBaseString.YES);

        return en;
    }
}
